package cn.initcap.concurrency.concurrency.aqs;

import java.util.concurrent.FutureTask;
import lombok.extern.slf4j.Slf4j;

/**
 * 当使用线程需要关注返回结果和运行状态时，推荐使用 FutureTask的方式。
 *
 * @author initcap
 * @date Created in 2018/6/18 PM12:02.
 */
@Slf4j
public class FutureTaskExample {

    public static void main(String[] args) throws Exception {
        FutureTask<String> futureTask = new FutureTask<>(() -> {
            log.info("do something in callable");
            Thread.sleep(5000);
            return "Done";
        });

        new Thread(futureTask).start();
        log.info("do something in main");
        String result = futureTask.get();
        log.info("resutl : {}", result);
    }

}
